package io.adminboot.web;

import io.adminboot.domain.param.JqGridParam;
import io.adminboot.domain.vo.PageVO;
import io.adminboot.entity.ScheduleJobLog;
import io.adminboot.service.ScheduleJobLogService;
import io.adminboot.utils.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 定时任务日志
 *
 */
@RestController
@RequestMapping("/sys/scheduleLog")
public class ScheduleJobLogController {
	@Autowired
	private ScheduleJobLogService scheduleJobLogService;
	
	/**
	 * 定时任务日志列表
	 */
	@GetMapping("/list")
//	@RequiresPermissions("sys:schedule:log")
	public R list(JqGridParam param) {
		Long jobId = null;
		Map<String, String> map = param.getKeywords();
		if (map != null && StringUtils.isNotBlank(map.get("jobId"))) {
			jobId = Long.valueOf(map.get("jobId"));
		}
		PageVO page = scheduleJobLogService.queryPage(jobId, param.getPageNum(), param.getPageSize());
		
		return R.ok().put("page", page);
	}
	
	/**
	 * 定时任务日志信息
	 */
	@GetMapping("/info/{logId}")
	public R info(@PathVariable("logId") Long logId){
		ScheduleJobLog log = scheduleJobLogService.selectById(logId);
		
		return R.ok().put("log", log);
	}
}
